/**
 * Apr 27, 2010
 */
package org.tomale.id.inventory.management.ui.wizards;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PartInitException;
import org.tomale.id.inventory.management.Activator;
import org.tomale.id.inventory.management.ui.ItemEditor;
import org.tomale.id.inventory.management.ui.ItemEditorInput;

/**
 * @author ferd
 *
 */
public class ItemWizard extends Wizard implements INewWizard {

	ItemOverviewPage _overview;
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
	@Override
	public boolean performFinish() {
		String name = _overview.getItemName();
		String desc = _overview.getItemDescription();
		
		try {
			ItemEditorInput input = new ItemEditorInput(name, desc);
			Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, ItemEditor.EDITOR_ID);
			return true;
		}catch(PartInitException e){
			_overview.setErrorMessage(e.getMessage());
			Activator.logError(e.getMessage());
			return false;
		}
	}

	@Override
	public void addPages() {
		_overview = new ItemOverviewPage();
		addPage(_overview);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
	 */
	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		// TODO Auto-generated method stub

	}

}
